#!/bin/bash
# 解析参数 --mode 和 --HOST_IP
MODE=""
HOST_IP=""

while [[ $# -gt 0 ]]; do
    key="$1"
    case $key in
        --mode)
        MODE="$2"
        shift # 跳过参数值
        shift
        ;;
        --HOST_IP)
        HOST_IP="$2"
        shift
        shift
        ;;
        *)
        # 未知参数
        shift
        ;;
    esac
done

# 如果未指定--mode，默认为"qemu"
if [[ -z "$MODE" ]]; then
    MODE="qemu"
fi

if [[ "$MODE" != "qemu" && "$MODE" != "BMC" ]]; then
    echo "❌ --mode 仅支持 'qemu' 或 'BMC'"
    exit 1
fi

# 根据mode设置HOST_IP
if [[ "$MODE" == "qemu" ]]; then
    HOST_IP="127.0.0.1"
elif [[ "$MODE" == "BMC" ]]; then
    if [[ -z "$HOST_IP" ]]; then
        HOST_IP="192.168.2.100"
    fi
fi

echo "当前模式: $MODE"
echo "BMC主机IP: $HOST_IP"

echo "=====create env ====="
python3 -m venv python_openubmc
source python_openubmc/bin/activate
pip install requests

echo "=====Install dependency====="
python3 smoke_test/install_dependency.py

echo "=====Connect to BMC====="
ps aux | grep qemu
python3 smoke_test/execute.py --HOST_IP $HOST_IP

echo "=====Start smoke testing====="
python3 smoke_test/testing.py --HOST_IP $HOST_IP